home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / www / src / WWW / MailRobot / Implementation / commands.c next >
Encoding:
C/C++ Source or Header  |  1992-10-19  |  4.0 KB  |  184 lines

  1. #include "listserv.h"
  2.  
  3. extern FILE *msg;
  4. extern FILE *mailer;
  5.  
  6. /*        Return simple HELP file
  7. */
  8. sendhelp(from,request)
  9. char *from, *request;
  10.     {
  11.     printf("called sendhelp with %s %s\n", from, request);
  12.     callmailer("", from, request);
  13.     mailcat(HELPFILE,"");
  14.     pclose(mailer);
  15.     return;
  16.     }
  17.  
  18. /*        Send information about mailing lists
  19. */
  20. listhelp(from,grp,request)
  21. char *from,*grp,*request;
  22.     {
  23.     char tmp[128];
  24.     printf("called listhelp with %s %s %s\n", from,grp,request);
  25.  
  26.     sprintf(tmp,"%s/%s.info", SERVDIR, grp);
  27.     if (access(tmp,R_OK) != 0)
  28.         {
  29.         callmailer("", from, request);
  30.         fprintf(mailer,"The mailing list \"%s\" could not be found.\n",
  31.             grp);
  32.         fprintf(mailer,"You may use the INDEX command to get a listing\n");
  33.         fprintf(mailer,"of available mailing lists.\n");
  34.         fflush(mailer);
  35.         pclose(mailer);
  36.         return;
  37.         }
  38.  
  39.     callmailer("", from, request);
  40.     fprintf(mailer,"Mailing list \"%s\":\n", grp);
  41.     mailcat(tmp,"\t");
  42.     pclose(mailer);
  43.     return;
  44.     }
  45.  
  46.  
  47. /*        INDEX command
  48. **        -------------
  49. */
  50. sendindex(from,request,l)
  51. char *from,*request;
  52. int l;
  53.     {
  54.     FILE *ls;
  55.     char tmp[128];
  56.     char buf[128];
  57.     int i;
  58.     printf("called sendindex with %s %s %d\n", from,request,l);
  59.  
  60.     sprintf(tmp,"cd %s; /bin/ls -1 *.info | sed -e 's/.info//'", SERVDIR);
  61.     ls = popen(tmp,"r");
  62.     if (ls == NULL)
  63.         {
  64.         perror(tmp);
  65.         exit(1);
  66.         }
  67.     callmailer("", from, request);
  68.     fprintf(mailer,"Index of mailing lists\n");
  69.  
  70.     /* read the result of the ls */
  71.     while (fgets(tmp, sizeof(tmp), ls))
  72.         {
  73.         while (tmp[(i=strlen(tmp)-1)] == '\n')
  74.             tmp[i] = '\0';
  75.         fprintf(mailer, "\t%s\n", tmp);
  76.  
  77.         /* if he wanted the long listing, cat the .info file */
  78.         if (l)
  79.             {
  80.             sprintf(buf, "%s/%s.info", SERVDIR, tmp);
  81.             mailcat(buf,"\t");
  82.             fprintf(mailer, "\n");
  83.             }
  84.         }
  85.     fprintf(mailer,"That's all.\n");
  86.     pclose(ls);
  87.     pclose(mailer);
  88.     return;
  89.     }
  90.  
  91. /*        SEND command
  92. **        ------------
  93. */
  94. #define MAX_LINES 1000
  95. char * valid_chars =
  96.   "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:/._-+@%*()";
  97. senddoc(from,request)
  98. char *from,*request;
  99.     {
  100.     FILE *ls;
  101.     char tmp[1024];
  102.     char buf[1024];
  103.     char udi[1024];
  104.     int i;
  105.     int lines = 0;
  106.     int valid[256];
  107.  
  108.     /*     Set up array of valid characters */
  109.     { int i;
  110.         char * p;
  111.         for(i=0; i<256; i++) valid[i]=0;
  112.         for (p=valid_chars; *p; p++) {
  113.         valid[(int)*p]=1;
  114.         }
  115.     }
  116.     
  117.     printf("called senddoc with %s %s\n", from,request);
  118.  
  119.     {
  120.         int words = sscanf(request, "%s%s%s", tmp, udi);
  121.         char *p;
  122.         
  123.         if (words != 2) goto error;
  124.         for (p=udi; *p; p++) {
  125.         if (!valid[*p]) goto error;
  126.         }
  127.  
  128.     }
  129.     
  130.     /* Start a WWW subprocess to read the info */
  131.     sprintf(tmp,
  132.     "%s -h \"%s\" -w72 -l %s -n -listrefs \"%s\"",
  133.         SECUREWWW, from, SENDLOGFILE, udi);
  134.     ls = popen(tmp,"r");
  135.     if (ls == NULL)
  136.         {
  137.         perror(tmp);
  138.         exit(1);
  139.         }
  140.     callmailer("", from, request);
  141.     fprintf(mailer,
  142.     "The requested document follows. Linked documents may be obtained\n");
  143.     fprintf(mailer,
  144.     "using SEND <address> where the addresses are listed at the end.\n");
  145.     fprintf(mailer,
  146.     "________________________________________________________________________\n");
  147.  
  148.     /* read the result of the www */
  149.     while (fgets(tmp, sizeof(tmp), ls)) {
  150.         while (tmp[(i=strlen(tmp)-1)] == '\n')
  151.             tmp[i] = '\0';
  152.         fprintf(mailer, "%s\n", tmp);
  153.         if (lines++ > MAX_LINES) {
  154.             fprintf(mailer,
  155.         "___________________________\n");
  156.         fprintf(mailer,
  157.         " ** Truncated: Limit of %d lines enforced by w3 listserv\n",
  158.             MAX_LINES);
  159.         }
  160.     }
  161.     pclose(ls);
  162.     pclose(mailer);
  163.     return;
  164. error:
  165.     {
  166.     callmailer("", from, request);
  167.     fprintf(mailer,"Your command\n\n");
  168.     fprintf(mailer,"\t%s\n", request);
  169.     fprintf(mailer,"could not be processed.\n%s\nCorrect syntax is\n\n");
  170.     fprintf(mailer,"\tSEND doc-address\n\n");
  171.     fprintf(mailer,"Where doc-address is the address of the document you want.\n");
  172.     fprintf(mailer,"(WWW is a synonym for SEND).\n");
  173.     fprintf(mailer,"Valid characters in the doc-address are:\n");
  174.     fprintf(mailer,"\"%s\"\n", valid_chars);
  175.     fprintf(mailer,"There is a limit of %d lines on any returned message.\n",
  176.             MAX_LINES);
  177.     fflush(mailer);
  178.     pclose(mailer);
  179.     return(-1);
  180.     }
  181.  
  182. }
  183.  
  184.